home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / DJGPP / mouse.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  2KB  |  113 lines

  1. /* --------------------------------- mouse.c -------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Handler for the mouse as a pointing device.
  8. */
  9.  
  10. #include "fly.h"
  11.  
  12. #include <graphics.h>
  13. #include <mouse.h>
  14.  
  15.  
  16. #define USELOG        0x0001        /* log scale on x/y (default) */
  17.  
  18. #define PO        p->opt
  19. #define FA1D        PO[0]
  20. #define FA1F        PO[1]
  21. #define FA2D        PO[2]
  22. #define FA2F        PO[3]
  23. #define FSPEEDX        PO[4]
  24. #define FSPEEDY        PO[5]
  25. #define FOPTS        PO[6]
  26.  
  27. static int    speed = 2;
  28.  
  29. static int FAR
  30. MUcal (POINTER *p)
  31. {
  32.     MouseWarp (GrMaxX()/2, GrMaxY()/2);
  33.     p->a[FA1F] = p->a[FA2F] = 0;
  34.     p->l[FA1F] = p->l[FA2F] = 0;
  35.     return (0);
  36. }
  37.  
  38. static int FAR
  39. MUinit (POINTER *p, char *options)
  40. {
  41.     long        l;
  42.  
  43.     MouseSetSpeed (speed);
  44.     p->flags |= PF_INITED;
  45.  
  46.     if (get_narg (options, "sx=", &l))
  47.         FSPEEDX = 2;
  48.     else
  49.         FSPEEDX = (int)l;
  50.  
  51.     if (get_narg (options, "sy=", &l))
  52.         FSPEEDY = 2;
  53.     else
  54.         FSPEEDY = (int)l;
  55.  
  56.     if (get_arg (options, "linear"))
  57.         FOPTS &= ~USELOG;
  58.     else
  59.         FOPTS |= USELOG;
  60.  
  61.     MUcal (p);
  62.  
  63.     return (0);
  64. }
  65.  
  66. static void FAR
  67. MUterm (POINTER *p)
  68. {
  69.     p->flags = 0;
  70. }
  71.  
  72. static int FAR
  73. MUread (POINTER *p, int transfer)
  74. {
  75.     MouseEvent    event[1];
  76.     char        btn[2];
  77.     int        reading;
  78.  
  79.     MouseGetEvent (M_POLL|M_NOPAINT, event);
  80.  
  81.     reading = GrMaxX();
  82.     reading = muldiv (event->x, 200, reading) - 100;    /* x */
  83.     reading *=  -PO[0];
  84.     p->a[FA2F] = reading;
  85.     if (transfer)
  86.         p->l[FA2F] = (FOPTS & USELOG) ? lin2log (reading) : reading;
  87.  
  88.     reading = GrMaxY();
  89.     reading = muldiv (event->y, 200, reading) - 100;    /* y */
  90.     reading *=  PO[2];
  91.     if (transfer)
  92.         p->l[FA1F] = (FOPTS & USELOG) ? lin2log (reading) : reading;
  93.  
  94.     btn[0] = event->buttons & M_LEFT;        /* right button */
  95.     btn[1] = event->buttons & M_RIGHT;        /* left button */
  96.  
  97.     do_btns (p, btn, sizeof (btn));
  98.  
  99.     return (0);
  100. }
  101.  
  102. struct PtrDriver NEAR PtrMouse = {
  103.     "MOUSE",
  104.     0,
  105.     NULL,    /* extra */
  106.     MUinit,
  107.     MUterm,
  108.     MUcal,
  109.     MUcal,            /* center */
  110.     MUread,
  111.     std_key
  112. };
  113.